package com.sl.hx.shop.ui.home.adapter;

import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.ImageView;
import android.widget.ProgressBar;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sl.hx.shop.R;
import com.sl.hx.shop.bean.CollectGoodsBean;
import com.sl.hx.shop.bean.FlashSaleList;

import java.text.DecimalFormat;
import java.util.List;

public class FlashSaleAdapter extends BaseQuickAdapter<FlashSaleList, BaseViewHolder> {

    private Double total;//总库存
    private Double sold; //已抢购数量
    private Double num; //余量

    public FlashSaleAdapter(@Nullable List<FlashSaleList> data) {
        super(R.layout.item_flashsale, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FlashSaleList item) {
        ImageView imageView = helper.getView(R.id.icon);
        Glide.with(mContext).load(item.getPic_url()).apply(RequestOptions.placeholderOf(R.drawable.classify_bitmap)).into(imageView);

        DecimalFormat df = new DecimalFormat("0");//格式化小数
        total = Double.valueOf(item.getTotal_amount());
        sold = Double.valueOf(item.getSold_num());
        num=(total - sold)/total*100;


        ProgressBar progressBar = helper.getView(R.id.progressBarHorizontal);
        progressBar.setProgress(Integer.valueOf(df.format(num)));

        helper.setText(R.id.title, item.getTitle())
                .setText(R.id.zk_final_price, item.getZk_final_price()+"")
                .setText(R.id.sold_num, "已抢" + item.getSold_num())
                .setText(R.id.Surplus, "剩余" + df.format(num) + "%");
    }
}
